/**
 * long description for the file
 *
 * @summary 添加网站
 * @author wu[308822989@qq.com]
 *
 * Created at     : 2018-12-17 14:23:20
 * Last modified  : 2018-12-19 09:05:35
 */

var app = new Vue({
    el: '#app',
    data: {
        tabs: 1,
        list: [],
        list2: [],
        code: '',
        pwd: '',
        login: {
            web_name: '',
            web_user: '',
            web_pwd: '',
            web_url: ''
        },
        //  是否打开添加弹窗
        openModal: false,
        //
        oList: [],
        oLogin: {
            source_name: '',
            source_aurl: '',
            source_matchlist: '',
            source_matchurl: '',
            source_matchtitle: '',
            source_matchbody: '',
            source_mid: '',
            type: 'source_matchlist'
        },
        //  是否打开添加弹窗
        openModal2: false,
    },
    mounted: function () {
        this.getList();
        this.getList2();
    },
    methods: {
        getList: function () {
            let that = this;
            axios.get('/web/list', {params: {pageIndex: 1, pageSize: 1000}}).then(function (res) {
                if (res.status === 200 && res.data && res.data.errno === 0) {
                    //  成功
                    that.list = res.data.data.data;
                } else {
                    //  失败
                    $.toast(res.data.errmsg || "添加失败",'text');
                }
            });
        },
        openAdd: function () {
            this.openModal = true;
        },
        add: function() {
            let that = this;
            axios.post('/web/add', this.login).then(function (res) {
                if (res.status === 200 && res.data && res.data.code === 0) {
                    //  成功
                    $.toast("添加成功", 'text');
                    setTimeout(function() {
                        that.openModal = false;
                        that.login = {
                            web_name: '',
                            web_user: '',
                            web_pwd: '',
                            web_url: ''
                        };
                    }, 1000);
                } else {
                    //  失败
                    $.toast(res.data.errmsg || "添加失败",'text');
                }
            });
        },
        openAdd2: function () {
            this.openModal2 = true;
        },
        test: function () {
            let that = this;
            axios.post('/match/test', this.oLogin).then(function (res) {
                if (res.status === 200 && res.data && res.data.errno === 0) {
                    //  成功
                    console.log(res)
                } else {
                    //  失败
                    $.toast(res.data.msg || "添加失败",'text');
                }
            });
        },
        addSource: function() {
            let that = this;
            axios.post('/web/addsource', this.oLogin).then(function (res) {
                if (res.status === 200 && res.data && res.data.errno === 0) {
                    //  成功
                    $.toast("添加成功", 'text');
                    setTimeout(function() {
                        that.openModal = false;
                        that.login = {
                            source_name: '',
                            source_aurl: '',
                            source_matchlist: '',
                            source_matchurl: '',
                            source_matchtitle: '',
                            source_matchbody: '',
                            source_mid: '',
                            type: 'source_matchlist'
                        };
                    }, 1000);
                } else {
                    //  失败
                    $.toast(res.data.msg || "添加失败",'text');
                }
            });
        },
        getList2: function () {
            let that = this;
            axios.get('/web/source', {params: {pageIndex: 1, pageSize: 1000}}).then(function (res) {
                if (res.status === 200 && res.data && res.data.errno === 0) {
                    //  成功
                    that.list2 = res.data.data.data;
                } else {
                    //  失败
                    $.toast(res.data.msg || "添加失败",'text');
                }
            });
        },
        openMdSource:function (item) {
            this.oLogin = $.extend(this.oLogin, item);
            this.openModal2 = true;
        }
    }
});
